package com.googlecode.jlogalizer.mapred.log.format;

import java.io.IOException;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.RecordWriter;
import org.apache.hadoop.mapred.lib.MultipleTextOutputFormat;
import org.apache.hadoop.util.Progressable;

import com.googlecode.jlogalizer.mapred.util.LogParser;

public class ClientIdMultipleTextOutputFormat extends MultipleTextOutputFormat<Text, IntWritable> {

	
	JobConf job;
	@Override
	public RecordWriter<Text, IntWritable> getRecordWriter(FileSystem fs,
			JobConf job, String name, Progressable arg3) throws IOException {
		// TODO Auto-generated method stub
		this.job=job;
		return super.getRecordWriter(fs, job, name, arg3);
	}
	
	
	@Override
	protected String generateFileNameForKeyValue(Text key, IntWritable value, String name) {
		//return (LogParser.getInstance().getSplitMemberFromString(key.toString(),0)+"/"+name);
		name=job.get("JOB_NAME");
		return (LogParser.getInstance().getSplitMemberFromString(key.toString(),0)+"/"+name);
		//return (LogParser.getInstance().getSplitMemberFromString(key.toString(),0));
		
	}

	
	@Override
	protected Text generateActualKey(Text key, IntWritable value) {
		return new Text(LogParser.getInstance().getSplitMemberFromString(key.toString(),1));
	}
	
	
	/*@Override
	protected String getInputFileBasedOutputFileName(JobConf conf, String name) {
		return (conf.get("JOB_NAME"));
	}*/
}
